package org.awenlice.playerdailyshop.data;

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.storage.DimensionDataStorage;

public class PlayerShopDataManager {
    private static final String DATA_NAME = "playerSellShopData_"; // 数据名称前缀

    public static PlayerShopData get(ServerPlayer player) {
        ServerLevel level = (ServerLevel) player.level(); // 获取 ServerLevel
        DimensionDataStorage storage = level.getDataStorage(); // 获取 DimensionDataStorage

        // 使用玩家 UUID 作为数据名称，确保唯一性
        String dataName = DATA_NAME + player.getUUID().toString();
        return storage.computeIfAbsent(PlayerShopData::load, PlayerShopData::new, dataName);
    }
}